package com.yiqi.liebang.feature.mine.view.adapter.edit;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.util.DateTool;
import com.yiqi.liebang.entity.bo.WorkBo;
import com.yiqi.liebang.entity.enums.CertificationStauts;
import com.yiqi.liebang.feature.mine.view.AllCertificationActivity;
import com.yiqi.liebang.feature.mine.view.ExpertCertificationActivity;
import com.yiqi.liebang.feature.mine.view.UploadWorkActivity;
import com.yiqi.liebang.feature.mine.view.adapter.WorkEditAdapter;
import com.yiqi.liebang.feature.setting.view.ImageActivity;

import java.io.Serializable;

import butterknife.BindView;

public class WorkInfoAdpter extends BaseQuickAdapter<WorkBo, BaseViewHolder> {

    public WorkInfoAdpter() {
        super(R.layout.item_work_list_ago);
    }

    @Override
    protected void convert(BaseViewHolder helper, WorkBo item) {
        AM.image().bindToCircleObject(item.getComLogo(), helper.getView(R.id.iv_work_company_logo));
        helper.setText(R.id.iv_work_company_name, item.getCompany())
                .setText(R.id.iv_work_company_date, item.getBeginTime() + " - " + item.getEndTime() + " , " + item.getPosition())
                .setText(R.id.tv_work_company_stauts, CertificationStauts.getName(item.getStatus()))
                .setImageResource(R.id.iv_work_company_stauts, item.getStatus() == 1 ? R.drawable.icon_yanzheng : R.drawable.icon_weiyanzhneg)
                .setText(R.id.iv_work_update_time, item.getImg() != null && item.getImg().size() > 0 ? DateTool.formatTime(item.getImg().get(0).getCreateTime()) : "")
                .addOnClickListener(R.id.btn_update_ziliao)
                .addOnClickListener(R.id.btn_upload_adapter)
        ;


        RecyclerView mRvWorkList = helper.getView(R.id.rv_work_list);
        mRvWorkList.setLayoutManager(new GridLayoutManager(AM.app(), 4));
        WorkEditAdapter documentAdapter = new WorkEditAdapter();
        documentAdapter.bindToRecyclerView(mRvWorkList);

        if (item.getImg() != null && item.getImg().size() > 0) {
            documentAdapter.setNewData(item.getImg());
            helper.getView(R.id.view_stauts).setVisibility(View.VISIBLE);
            helper.getView(R.id.btn_upload_adapter).setVisibility(View.GONE);
        }else {

            helper.getView(R.id.btn_upload_adapter).setVisibility(View.VISIBLE);
            helper.getView(R.id.view_stauts).setVisibility(View.GONE);
        }

        documentAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intentWork = new Intent(mContext, ImageActivity.class);
                intentWork.putExtra("pos", position);
                intentWork.putExtra("images", (Serializable) item.getImg());
                mContext.startActivity(intentWork);
            }
        });

    }
}
